package com.blb.service.impl;

import com.blb.mapper.MediaCoverageDao;
import com.blb.pojo.MediaCoverage;
import com.blb.pojo.vo.MediaCoverageVo;
import com.blb.service.MediaCoverageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author： yrh
 * @ClassName: MediaCoverageServiceImpl
 * @Description: 媒体报道逻辑层实现类
 * @Date: Created in 17:46 2022/1/5
 * @Version 1.0
 */
@Service
public class MediaCoverageServiceImpl implements MediaCoverageService {
    @Autowired
    private MediaCoverageDao mediaCoverageDao;
    @Override
    //根据年份返回数据
    public List<MediaCoverageVo> selectAll() {
        //获取年份
        List<MediaCoverageVo> mediaCoverageVos = new ArrayList<>();
        List<String> time = mediaCoverageDao.selectOrTime();
        List<MediaCoverage> list = mediaCoverageDao.selectAll();
//        //根据年份统计新闻
        for (String s : time){
            ArrayList<MediaCoverage> lists = new ArrayList<>();
            for (MediaCoverage coverage : list) {
                if (s.equals(coverage.getMediaTime().substring(0,4))){
                    lists.add(coverage);
                }
            }
            MediaCoverageVo mediaCoverageVo = new MediaCoverageVo(s,lists);
            mediaCoverageVos.add(mediaCoverageVo);
        }
        return mediaCoverageVos;
    }
}
